﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using FwProject.Configuration;
using FwProject.Web;

namespace FwProject.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class FwProjectDbContextFactory : IDesignTimeDbContextFactory<FwProjectDbContext>
    {
        public FwProjectDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<FwProjectDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            FwProjectDbContextConfigurer.Configure(builder, configuration.GetConnectionString(FwProjectConsts.ConnectionStringName));


            return new FwProjectDbContext(builder.Options);
        }
    }
}
